package com.v.im.businessservice.service.impl;

import com.fasterxml.jackson.databind.util.BeanUtil;
import com.v.im.businessapi.dto.resultDTO.ImChatGroupUserResultDTO;
import com.v.im.businessservice.bean.ImChatGroupUserEntity;
import com.v.im.businessservice.service.base.BaseService;
import com.v.im.businessservice.service.iface.IImChatGroupUserService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ImChatGroupUserServiceImpl extends BaseService implements IImChatGroupUserService {

    @Override
    public List<ImChatGroupUserResultDTO> getImChatGroupUserResults(String chatGroupId) {
        List<ImChatGroupUserEntity> imChatGroupUserEntities = imChatGroupUserDao.findByChatGroupId(chatGroupId);
        List<ImChatGroupUserResultDTO> imChatGroupUserResultDTOS = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(imChatGroupUserEntities)) {
            for (ImChatGroupUserEntity imChatGroupUserEntity : imChatGroupUserEntities) {
                ImChatGroupUserResultDTO imChatGroupUserResultDTO = new ImChatGroupUserResultDTO();
                BeanUtils.copyProperties(imChatGroupUserEntity, imChatGroupUserResultDTO);
                imChatGroupUserResultDTOS.add(imChatGroupUserResultDTO);
            }
        }
        return imChatGroupUserResultDTOS;
    }
}
